$(function(){
	if($(".admin").height()<600){
		$('.nav-btn').height('50px').find('img').hide();
	}else{
		$('.nav-btn').height('150px').find('img').show();
	}
})
//	物料登记
	var pageSize = 15;
	var currentPage = 1; 
	ajaxTest(currentPage);
	
	function ajaxTest(currentPage) {
		$.ajax({
				type:"post",
				url:serverIP+"/user/goods/list",
				dataType:"json",
				xhrFields: {
	                withCredentials: true    // 设置sessionId相同
	            },
	            data: {page:currentPage,pageSize:pageSize},
				success:function (data) {
					if(data.code==0){
						let result=data.data.list.result;
						var strVar = "";
						result.map(function(u){
							strVar += "              <tr>";
						    strVar += "                <td>"+u.goodsId+"<\/td>\n";
						    strVar += "                <td>"+u.name+"<\/td>\n";
						    strVar += "                <td>"+u.brandName+"<\/td>\n";
						    strVar += "                <td>"+u.modelName+"<\/td>\n";
						    strVar += "                <td>"+u.type+"<\/td>\n";
						    strVar += "                <td>"+u.format+"<\/td>\n";
						    strVar += "                <td>"+u.unitName+"<\/td>\n";
						    strVar += "                <td>"+u.colorName+"<\/td>\n";
						    strVar += "                <td>"+u.warnNum+"<\/td>\n";
						    strVar += "                <td class=\"noExl\">\n"; 
						    strVar += "                		<div>\n"; 
						    strVar += "                			<span class=\"btn detail\" value="+u.goodsId+">\n"; 
						    strVar += "                				<i class=\"icon-flag\"></i>供应商\n"; 
						    strVar += "                			</span>\n"; 
						    strVar += "                			<span class=\"btn edit\" value="+u.goodsId+">\n"; 
						    strVar += "                				<i class=\"icon-edit\"></i>编辑\n"; 
						    strVar += "                			</span>\n"; 
						    strVar += "                			<span class=\"btn delete\" value="+u.goodsId+">\n"; 
						    strVar += "                				<i class=\"icon-trash\"></i>删除\n"; 
						    strVar += "                			</span>\n";
						    strVar += "                		</div>\n";
						    strVar += "                <\/td>\n"; 
						    strVar += "              <\/tr>";
						})
						$('.print-tbody').html(strVar);
					//分页
						$("#page").paging({
							pageNo: data.data.list.curPage,
							totalPage: data.data.list.totalPage,
							totalSize: data.data.list.totalRow,
							callback: function(currentPage) {
								ajaxTest(currentPage); 
							}
						});
					}else{
						alert(data.msg);
						window.location.href="login.html";
					}/*if-End*/
				}
		})
	}
$("body").on("click",".detail",function(){
	var id=$(this).attr("value");
	window.location.href="stock1.html?id="+id;
})
$("body").on("click",".edit",function(){
	var id=$(this).attr("value");
	window.location.href="stock-edit.html?id="+id;
})
$("body").on("click",".delete",function(){
	if(confirm("确定要删除本条信息么")){
		var id=$(this).attr("value");
		$.ajax({  
	        type : "POST",  
	        url : serverIP+'/user/goods/del',  
	        data : {
	        	 goodsId:id
	        },
	        xhrFields: {
	            withCredentials: true    // 设置sessionId相同
	        },
	        success : function(data){  
	        	if(data.code==0){
	        		alert("删除成功");
	        		window.location.onload();
	        	}else{
	        		alert(data.msg);
	        	}
	        }  
	    });
	}
});   
$(".add").click(function(){
	window.location.href="stock-enter.html";
})
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
	if($(".admin").height()<600){
		$('.nav-btn').height('50px').find('img').hide();
	}else{
		$('.nav-btn').height('150px').find('img').show();
	}
}